import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
 roles: ['admin','editor']    control the page roles (you can set multiple roles)
 title: 'title'               the name show in sidebar and breadcrumb (recommend set)
 icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
 breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
 activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
 }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/form-design',
    component: () => import('@/views/form-design/index'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  },
  {
    path: '/process',
    component: Layout,
    meta: { title: '流程任务', icon: 'el-icon-s-tools' },
    name: '系统管理',
    children: [
      {
        path: 'todo',
        name: 'TodoTask',
        component: () => import('@/views/bpm/todo/index'),
        meta: { title: '待办任务', icon: 'el-icon-menu' }
      },
      {
        path: 'done',
        name: 'DoneTask',
        component: () => import('@/views/bpm/done/index'),
        meta: { title: '已办任务', icon: 'el-icon-s-data' }
      },
      {
        path: 'start',
        name: 'ProcessStart',
        component: () => import('@/views/bpm/start/index'),
        meta: { title: '流程发起', icon: 'el-icon-s-data' }
      },
      {
        path: 'history',
        name: 'ProcessHistory',
        component: () => import('@/views/bpm/process/index'),
        meta: { title: '已办流程', icon: 'el-icon-s-data' }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    meta: { title: '系统管理', icon: 'el-icon-s-tools' },
    name: '系统管理',
    children: [
      {
        path: 'menu',
        name: 'SystemMenu',
        component: () => import('@/views/system/menu/index'),
        meta: { title: '菜单管理', icon: 'el-icon-menu' }
      },
      {
        path: 'dict',
        name: 'SystemDictionary',
        component: () => import('@/views/system/dict/index'),
        meta: { title: '字典管理', icon: 'el-icon-s-data' }
      }
    ]
  },
  {
    path: '/manage',
    component: Layout,
    meta: { title: '流程管理', icon: 'el-icon-s-tools' },
    name: '流程管理',
    children: [
      {
        path: 'design',
        name: 'ProcessDesign',
        component: () => import('@/views/bpm/manage/design/index'),
        meta: { title: '流程设计', icon: 'el-icon-menu' }
      },
      {
        path: 'audit',
        name: 'ProcessAudit',
        component: () => import('@/views/bpm/manage/audit/index'),
        meta: { title: '流程审计', icon: 'el-icon-s-data' }
      },
      {
        path: 'designer',
        name: 'ProcessDesigner',
        hidden: true,
        component: () => import('@/views/bpm/manage/design/model-design'),
        meta: { title: '流程设计', icon: 'el-icon-s-data' }
      },
      {
        path: 'assign-rule',
        name: 'ProcessDesigner',
        hidden: true,
        component: () => import('@/views/bpm/manage/rule/index'),
        meta: { title: '流程规则', icon: 'el-icon-s-data' }
      }
    ]
  },
  {
    path: '/code',
    component: Layout,
    redirect: '/code/generator',
    name: '代码生成',
    meta: { title: '代码生成', icon: 'el-icon-s-platform' },
    children: [
      {
        path: 'generator',
        name: 'Generator',
        component: () => import('@/views/generator/code-generator'),
        meta: { title: '代码生成', icon: 'el-icon-s-help' }
      },
      {
        path: 'class',
        name: 'BaseClass',
        component: () => import('@/views/generator/base-class/index'),
        meta: { title: '基础类管理', icon: 'el-icon-mouse' }
      },
      {
        path: 'field',
        name: 'FieldType',
        component: () => import('@/views/generator/field-type/index'),
        meta: { title: '字段类型管理', icon: 'el-icon-s-grid' }
      },
      {
        path: 'form',
        name: 'Form',
        component: () => import('@/views/generator/form/index'),
        meta: { title: '表单管理', icon: 'el-icon-s-data' }
      }
    ]
  },
  {
    path: '/task',
    component: Layout,
    meta: { title: '任务处理', icon: 'el-icon-s-tools' },
    name: '系统管理',
    hidden: true,
    children: [
      {
        path: 'handle',
        name: 'TaskHandle',
        component: () => import('@/views/process/handle/index'),
        meta: { title: '任务处理', icon: 'el-icon-menu' }
      },
      {
        path: 'readonly',
        name: 'TaskReadonly',
        component: () => import('@/views/process/readonly/index'),
        meta: { title: '查看任务', icon: 'el-icon-s-data' }
      },
      {
        path: 'start',
        name: 'TaskStart',
        component: () => import('@/views/process/start/index'),
        meta: { title: '任务处理', icon: 'el-icon-s-data' }
      }
    ]
  },
  {
    path: '/monitor',
    component: Layout,
    meta: { title: '环境监测', icon: 'el-icon-s-tools' },
    name: 'MonitorManage',
    children: [
      {
        path: 'list',
        name: 'MonitorList',
        component: () => import('@/views/business/monitoring_collection/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'analysis',
        name: 'MonitorAnalysis',
        component: () => import('@/views/business/monitoring_analysis/index'),
        meta: { title: '数据分析', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'MonitorConfig',
        component: () => import('@/views/business/monitoring_configuration/index'),
        meta: { title: '数据阈值设置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/index',
    component: Layout,
    meta: { title: '环境指标', icon: 'el-icon-s-tools' },
    name: '环境指标',
    children: [
      {
        path: 'index-process',
        name: 'IndexList',
        component: () => import('@/views/business/emergency/index'),
        meta: { title: '指标盘', icon: 'el-icon-menu' }
      },
      {
        path: 'record',
        name: 'IndexRecord',
        component: () => import('@/views/business/emergency/index'),
        meta: { title: '数据录入', icon: 'el-icon-menu' }
      },
      {
        path: 'manage',
        name: 'IndexManage',
        component: () => import('@/views/business/emergency/index'),
        meta: { title: '指标管理', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'IndexManage',
        component: () => import('@/views/business/emergency/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/factor',
    component: Layout,
    meta: { title: '环境因素', icon: 'el-icon-s-tools' },
    name: 'FactorManage',
    children: [
      {
        path: 'factor-process',
        name: 'FactorStart',
        component: () => import('@/views/business/task_start/index'),
        meta: { title: '环境因素发起', icon: 'el-icon-menu' },
        query: { name: '测试流程', key: 'System_Test_02', desc: '测试流程发起', type: '' }
      },
      {
        path: 'list',
        name: 'FactorList',
        component: () => import('@/views/business/factor/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'FactorConfig',
        component: () => import('@/views/business/task_config/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/collect',
    component: Layout,
    meta: { title: '环境信息收集', icon: 'el-icon-s-tools' },
    name: 'InfoCollect',
    children: [
      {
        path: 'collect-process',
        name: 'CollectStart',
        component: () => import('@/views/business/task_start/index'),
        meta: { title: '发起数据填报任务', icon: 'el-icon-menu' },
        query: { name: '测试流程', key: 'System_Test_02', desc: '测试流程发起', type: '' }
      },
      {
        path: 'list',
        name: 'CollectList',
        component: () => import('@/views/business/protection_collection/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'CollectConfig',
        component: () => import('@/views/business/task_config/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/danger',
    component: Layout,
    meta: { title: '环境隐患排查', icon: 'el-icon-s-tools' },
    name: 'DangerManage',
    children: [
      {
        path: 'danger-process',
        name: 'DangerManage',
        component: () => import('@/views/business/task_start/index'),
        meta: { title: '发起数据填报任务', icon: 'el-icon-menu' },
        query: { name: '测试流程', key: 'System_Test_02', desc: '测试流程发起', type: '' }
      },
      {
        path: 'list',
        name: 'DangerList',
        component: () => import('@/views/business/hidden_danger/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'analysis',
        name: 'DangerAnalysis',
        component: () => import('@/views/business/hidden_analysis/index'),
        meta: { title: '数据分析', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'DangerConfig',
        component: () => import('@/views/business/task_config/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/procedure',
    component: Layout,
    meta: { title: '环保手续管理', icon: 'el-icon-s-tools' },
    name: 'ProcedureManage',
    children: [
      {
        path: 'procedure-process',
        name: 'ProcedureStart',
        component: () => import('@/views/business/task_start/index'),
        meta: { title: '环保手续任务发起', icon: 'el-icon-menu' },
        props: route => ({ query: { name: '测试流程', key: 'System_Test_02', desc: '测试流程发起', type: '' } })
      },
      {
        path: 'list',
        name: 'ProcedureList',
        component: () => import('@/views/business/protection_procedures/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'ProcedureConfig',
        component: () => import('@/views/business/task_config/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/emergency ',
    component: Layout,
    meta: { title: '环境应急预案', icon: 'el-icon-s-tools' },
    name: 'EmergencyManage',
    children: [
      {
        path: 'emergency-process',
        name: 'ProcedureStart',
        component: () => import('@/views/business/task_start/index'),
        meta: { title: '环保手续任务发起', icon: 'el-icon-menu' },
        props: route => ({ query: { name: '测试流程', key: 'System_Test_02', desc: '测试流程发起', type: '' } })
      },
      {
        path: 'list',
        name: 'ProcedureList',
        component: () => import('@/views/business/emergency/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'ProcedureConfig',
        component: () => import('@/views/business/task_config/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  {
    path: '/process ',
    component: Layout,
    meta: { title: '环境应急预案', icon: 'el-icon-s-tools' },
    name: 'EmergencyManage',
    children: [
      {
        path: 'emergency-process',
        name: 'ProcedureStart',
        component: () => import('@/views/business/task_start/index'),
        meta: { title: '环保手续任务发起', icon: 'el-icon-menu' },
        props: route => ({ query: { name: '测试流程', key: 'System_Test_02', desc: '测试流程发起', type: '' } })
      },
      {
        path: 'list',
        name: 'ProcedureList',
        component: () => import('@/views/business/emergency/index'),
        meta: { title: '数据查询', icon: 'el-icon-menu' }
      },
      {
        path: 'config',
        name: 'ProcedureConfig',
        component: () => import('@/views/business/task_config/index'),
        meta: { title: '自动提醒配置', icon: 'el-icon-menu' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
